var userInfo;
var uid;//nosession uid
var CONFIG_DATA={
	path : '/dpupload/'
	,actpath : '/dpupload/act/'
	,picpath : '/dpupload/pic/'
	,headpath : '/dpupload/head/'
	,buspicpath : '/dpupload/bus/'
	,FEETYPE :{'0':'免费','1':'请客','2':'线上支付','3':'线下支付'}
}
var Group_Id ='';
var ACT_TYPE_DATA = {'1':'餐饮','2':'体育','3':'其它'};
var PIC_TYPE = '';
var map;//地图信息
var __nameCardId = '';
var isLine = false;
var searchCon = '';
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F13a4adc1faaad3ff2aee7d80be79e219' type='text/javascript'%3E%3C/script%3E"));
//*###########################全局配置#############################*//
Jes.extend({
	/**
	* @todo：取得用户session信息
	* @author：hyh
	* type null=匿名用户也能访问 1=需要登陆才能访问
	*/
	userSess : function(type){
		Jes.doSync(function(){Jes.doAction("getUserSess",false,function(data){userInfo = data;});});
		if(!userInfo){
			if(type == 1){//登陆才能访问
				Jes.openLogin('goToTop','loginshow');
			}else{
				uid =Jes.request('uid');
				return false;
			}
			return false;
		}else{
			isLine = true;
			Jes.toplist();
			uid =Jes.request('uid');
			userInfo.uid = uid || userInfo.userid;
			return true;
		}
	}
	//登录
	,doLogin : function (reurl){
		DWRUtil.useLoadingMessage("正在登入中...");
		var param = Jes.getFormValue('login_from',0);
		if(param == null) return;
		Jes.doAction("doLogin@CnAction",param.email,param.password,1,function(url){
			if(param.repsd=='1'){
				Jes.ie({name:'cuniao.repsd',val:1,exp:7,path:'/cuniao/'}
				,{name:'cuniao.email',val:param.email,exp:7,path:'/cuniao/'}
				,{name:'cuniao.psd',val:param.password,exp:7,path:'/cuniao/'});
			}
			if(!Jes.userSess(1)) return;//session
			if(reurl==null||reurl==''){
				Jes.goUrl(url);
			}else{
				Jes.goUrl(reurl);
			}
		});
	}
	,doLogout : function(){
		Jes.doAction("removeSessAttr","USER_INFO");
		Jes.ie({name:'cuniao.repsd',val:null,exp:-1,path:'/cuniao/'},{name:'cuniao.psd',val:null,exp:-1,path:'/cuniao/'});
		Jes.goUrl('/cuniao/logout.html');
	}	
	,doSina : function (){
		Jes.doAction("doSina@CnAction",function(url){
			Jes.goUrl(url);
		});
	}
	,doTencent : function (){
		Jes.doAction("doTencent@CnAction",function(url){
			Jes.goUrl(url);
		});
	}	
	//直接判断是否在线,不必去后台查询
	,isOnline : function(){
		if(!isLine){
			Jes.openLogin('goToTop','loginshow');
		}else{
			return true;
		}
	}
	//顶部html
	,toplist : function(){
		html='<a href="../front/invite.html" style="color:red">邀请好友参加返5元</a><a target="_blank" href="../acl/modifyuser.html">账户设置</a><a href="javascript:void(0);" onclick="Jes.doLogout();">退出</a>';
		Jes.html('toplist',html);
	}
	,toInt : function(i){
		return parseInt(i);
	}
	,notnull : function(value){
		if(value==null){
			return '';
		}else{
			return value;
		}
	}
	,getsub : function(value,endindex){
		if(value.length>endindex){
			return value.substring(0,endindex)+'...';
		}else{
			return value;
		}
	}
    ,len : function(s) {
		 var l = 0;
		 var a = s.split("");
		 for (var i=0;i<a.length;i++) {
			  if (a[i].charCodeAt(0)<299) {
			   l++;
			  } else {
			   l+=2;
			  }
		 }
		 return l;
	}
	// 在中心位置显示隐藏域
	/*
	,showDiv : function (obj,divname,divvalue){
		if(Jes(divname)!=null&&Jes(divname)!=''){
			Jes(divname).value = divvalue;
		}
		if(obj==null)return;
		var pz = ___getPageSize(), ps = ___getPageScroll();
		var ow = Jes.width(obj),oh=Jes.height(obj);
		Jes.setStyle(obj,{
			top:(pz[3]-oh)/2 + ps[1],
			left:(pz[2]-ow)/2 +ps[0],
			display:'inline'
		});
	}*/
	,showDiv : function (obj,divname,divvalue){
		if(divname!=null&&divname!=''){//传值
			Jes(divname).value = divvalue;
		}
		var pz = ___getPageSize(), ps = ___getPageScroll();
		var ow = $(obj).width(),oh = $(obj).height();
		$(obj).css({
			top:(pz[3]-oh)/2 + ps[1],
			left:(pz[2]-ow)/2 +ps[0]
		}).show();
	}
	,getPosition : function (obj){
		var result = 0;
		if(obj.selectionStart){ //非IE浏览器
		     result = obj.selectionStart
		}else{ //IE
			var rng;
		    if(obj.tagName == "TEXTAREA"){ //如果是文本域
		    	rng = event.srcElement.createTextRange();
		        rng.moveToPoint(event.x,event.y);
		     }else{ //输入框
		        rng = document.selection.createRange();
		     }
		     rng.moveStart("character",-event.srcElement.value.length);
		     result = rng.text.length;
		}
		return result;
	}
	//重新userinfo在session中
	,syn : function(userId){
		Jes.doAction("doSyn@CnAction",userId,function(data){
		});
	}
	//alert
	,alert : function(alertInfo){
		if(Jes('alert')){
			Jes.showDiv('divalert','alert',alertInfo);
			Jes('alert').innerHTML = alertInfo;
			setTimeout("Jes.hide('divalert')",1300);
		}else{
			alert(alertInfo);
		}
	}
	//初始地图
	,initMap: function(mapId) {
		map = new BMap.Map(mapId);
		var opts = {type: BMAP_NAVIGATION_CONTROL_SMALL}
		map.addControl(new BMap.NavigationControl(opts));
		var point = new BMap.Point(120.144133,30.288999);//杭州
		map.centerAndZoom(point,15);
	}
	//的地址定位
    ,locate: function(address,mapId) {
    	if(!map){
    		map = new BMap.Map(mapId);
    		var opts = {type: BMAP_NAVIGATION_CONTROL_SMALL}
			map.addControl(new BMap.NavigationControl(opts));
    	}
		var myGeo = new BMap.Geocoder();
		map.clearOverlays();
		myGeo.getPoint(address, function(point){
		  if (point) {
		    map.centerAndZoom(point, 15);
		    map.addOverlay(new BMap.Marker(point));
		  }
		}, address.substr(0,3));
    }
	//取时间格式 return 2011-9-13  AddDayCount：几天后
	,getDateFormatStr : function (AddDayCount) {
    	var dd = new Date();
    	dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
    	var y = dd.getFullYear();
    	var m = dd.getMonth()+1;//获取当前月份的日期
    	var d = dd.getDate();
    	return y+'-'+m+'-'+d;
	}
	,getNow : function(){
		var dd = new Date();
		var m = dd.getMonth()+1;
		var ss = dd.getFullYear() +'-'+ m +'-'+dd.getDate() + ' '+ 
			dd.getHours().toString()+':'+dd.getMinutes().toString()+':'+dd.getSeconds().toString();
		return ss;
	}
	//取时间格式 return 2011-9-13  AddDayCount：几天后
	,getDoubleDateFormatStr : function (AddDayCount) {
    	var dd = new Date();
    	dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
    	var y = dd.getFullYear();
    	var m = dd.getMonth()+1;//获取当前月份的日期
    	var d = dd.getDate();
    	if((m+'').length==1)m='0'+m;
    	if((d+'').length)d='0'+d;
    	return y+'-'+m+'-'+d;
	}
	//取时间格式 return 9月13日  AddDayCount：几天后
	,getDateStr : function (AddDayCount) {
    	var dd = new Date();
    	dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
    	var y = dd.getFullYear();
    	var m = dd.getMonth()+1;//获取当前月份的日期
    	var d = dd.getDate();
    	return m+"月"+d+'日';
	}
	//取时间格式 return 9月13日  AddDayCount：几天后
	,getDateStrMoonDay : function (time) {
		if(time==null||time=='') return '';
		var dd= new Date(Date.parse(time.replace(/-/g, "/")));
    	var y = dd.getFullYear();
    	var m = dd.getMonth()+1;//获取当前月份的日期
    	var d = dd.getDate();
    	return m+"月"+d+'日';
	}
	//取时间格式 return 周四
	,getTimeWeekStr : function (Time,white) {
    	var dd= new Date(Date.parse(Time.replace(/-/g, "/")));
    	var ww = dd.getDay();
    	if (ww==0) ww="<font color=RED>周日</font>";
		if (ww==1) ww="周一";
		if (ww==2) ww="周二";
		if (ww==3) ww="周三";
		if (ww==4) ww="周四";
		if (ww==5) ww="<font color=RED>周五</font>";
		if (ww==6) ww="<font color=RED>周六</font>";
    	return ww;
	}
	//取时间格式 return 周四   AddDayCount：几天后
	,getWeekStr : function (AddDayCount) {
    	var dd = new Date();
    	dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
    	var ww = dd.getDay();
    	if (ww==0) ww="<font color=RED>周日</font>";
		if (ww==1) ww="周一";
		if (ww==2) ww="周二";
		if (ww==3) ww="周三";
		if (ww==4) ww="周四";
		if (ww==5) ww="<font color=RED>周五</font>";
		if (ww==6) ww="<font color=RED>周六</font>";
    	return ww;
	}
    //设置今天
    ,setToday : function(divName){
    	var date = Jes.getDateStr(0);
    	var week = Jes.getWeek(0);
    	var content = '';
    	Jes.html(divName,'<span>今天</span><span>'+ date + '</span><span>' + week+'</span>');
    	/*
    	Jes.doSync(function(){
    		//var weather = Jes.getWeather('杭州',0);
    		var cityname='杭州',day=0;
    		var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
			var serverPage = "http://php.weather.sina.com.cn/xml.php?city="+cityname+"&password=DJOYnieT8234jlsK&day="+day; 
		    xmlhttp.open("GET",serverPage); 
		    xmlhttp.setRequestHeader("Content-Type", "text/xml");
		    xmlhttp.onreadystatechange=function(){
		    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		    	var str =  xmlhttp.responseText;
		    	var i = str.indexOf('<status1>');
		    	var s1 =  str.substr(i+9,str.indexOf('</status1>')-9-i);
		    	var i = str.indexOf('<status2>');
		    	var s2 = str.substr(i+9,str.indexOf('</status2>')-9-i);
		    	if(s1!=s2){
		    		content= s1+'转'+s2;
		    	}else{
		    		content = s1;
		    	}
		     	var i = str.indexOf('<temperature2>');
		    	var s1 =  str.substr(i+14,str.indexOf('</temperature2>')-14-i);
		    	var i = str.indexOf('<temperature1>');
		    	var s2 = str.substr(i+14,str.indexOf('</temperature1>')-14-i);
		    	if(s1!=s2){
		    		content += s1+'～'+s2+'℃';
		    	}else{
		    		content += s1+'℃';
		    	}
		    	Jes.html(divName,'<span>今天</span><span>'+ date + '</span><span>' + week+'</span><span>' + content +'</span>');
		        }
		     }
		    xmlhttp.send(null);
    	});
    	*/
    }
	//根据城市名称得到天气信息 
 	,getWeather : function(cityname,day){
	var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
	var serverPage = "http://php.weather.sina.com.cn/xml.php?city="+cityname+"&password=DJOYnieT8234jlsK&day="+day; 
	    xmlhttp.open("GET",serverPage); 
	    xmlhttp.setRequestHeader("Content-Type", "text/xml");
	    xmlhttp.onreadystatechange=function(){
	    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
	    	var str =  xmlhttp.responseText;
	    	var content = '';
	    	var i = str.indexOf('<status1>');
	    	var s1 =  str.substr(i+9,str.indexOf('</status1>')-9-i);
	    	var i = str.indexOf('<status2>');
	    	var s2 = str.substr(i+9,str.indexOf('</status2>')-9-i);
	    	if(s1!=s2){
	    		content= s1+'转'+s2;
	    	}else{
	    		content = s1;
	    	}
	     	var i = str.indexOf('<temperature2>');
	    	var s1 =  str.substr(i+14,str.indexOf('</temperature2>')-14-i);
	    	var i = str.indexOf('<temperature1>');
	    	var s2 = str.substr(i+14,str.indexOf('</temperature1>')-14-i);
	    	if(s1!=s2){
	    		content += s1+'～'+s2+'℃';
	    	}else{
	    		content += s1+'℃';
	    	}
	    	alert(content);
	    	return content ;
	        }
	     }
	    xmlhttp.send(null);
	}
	//判断今天星期几
	,getWeek : function(AddDayCount){
		var d=new Date();
		d.setDate(d.getDate()+AddDayCount);
		var i = d.getDay();
		switch(i){
			case 0 : return '<font color=RED style="font-size:14px;">周日</font>';
			case 1 : return '星期一';
			case 2 : return '星期二';
			case 3 : return '星期三';
			case 4 : return '星期四';
			case 5 : return '<font color=RED style="font-size:14px;">星期五</font>';
			case 6 : return '<font color=RED style="font-size:14px;">星期六</font>';
		}
	}
	,copyUrl : function(name){
		var t=Jes(name);
		t.select();
		window.clipboardData.setData('text',t.createTextRange().text);
		alert("已复制,CTRL+V粘贴给好友即可");
	}
	//头像图片的处理
	,getPicPath : function(pic){
		if(pic.indexOf('http')!='-1'){
			return pic;
		}else{
			return CONFIG_DATA.headpath + pic;
		}
	}
	//隐藏展示
    ,showhidediv : function(id){
    	var sbtitle = document.getElementById(id);
        if (sbtitle) {
	        if (sbtitle.style.display == 'block') {
	        	sbtitle.style.display = 'none';
	        } else {
	            sbtitle.style.display = 'block';
			}
        }
	}
	,openLogin : function(objId,conId){
		var arrayPageSize   = ___getPageSize();//调用getPageSize()函数
		var arrayPageScroll = ___getPageScroll();//调用getPageScroll()函数
		//创建弹出背景层
		var bodyBack = document.createElement("div");
		bodyBack.setAttribute("id","bodybg")
		bodyBack.style.position = "absolute";
		bodyBack.style.width = "100%";
		bodyBack.style.height = (arrayPageSize[1] + 35 + 'px');
		bodyBack.style.zIndex = 98;
		bodyBack.style.top = 0;
		bodyBack.style.left = 0;
		bodyBack.style.filter = "alpha(opacity=50)";
		bodyBack.style.opacity = 0.5;
		bodyBack.style.background = "#ddf";
		var mybody = document.getElementById(objId);
		insertAfter(bodyBack,mybody);//执行函数insertAfter()
		Jes.showDiv('#'+conId);
	}
	//弹出层
	,openLayer : function(objId,conId){
		var arrayPageSize   = ___getPageSize();//调用getPageSize()函数
		var arrayPageScroll = ___getPageScroll();//调用getPageScroll()函数
		if (!document.getElementById("popupAddr")){
			//创建弹出内容层
			var popupDiv = document.createElement("div");
			//给这个元素设置属性与样式
			popupDiv.setAttribute("id","popupAddr")
			popupDiv.style.position = "absolute";
			popupDiv.style.border = "1px solid #ccc";
			popupDiv.style.background = "#fff";
			popupDiv.style.zIndex = 99;
			//创建弹出背景层
			var bodyBack = document.createElement("div");
			bodyBack.setAttribute("id","bodybg")
			bodyBack.style.position = "absolute";
			bodyBack.style.width = "100%";
			bodyBack.style.height = (arrayPageSize[1] + 35 + 'px');
			bodyBack.style.zIndex = 98;
			bodyBack.style.top = 0;
			bodyBack.style.left = 0;
			bodyBack.style.filter = "alpha(opacity=50)";
			bodyBack.style.opacity = 0.5;
			bodyBack.style.background = "#ddf";
			//实现弹出(插入到目标元素之后)
			var mybody = document.getElementById(objId);
			insertAfter(popupDiv,mybody);//执行函数insertAfter()
			insertAfter(bodyBack,mybody);//执行函数insertAfter()
		}
		//显示背景层
		document.getElementById("bodybg").style.display = "";
		//显示内容层
		var popObj=document.getElementById("popupAddr");
		var arrayConSize;
		popObj.innerHTML = document.getElementById(conId).innerHTML;
	//	Jes.showDiv(popupAddr);
		arrayConSize=getConSize(conId);
		popObj.style.display = "";
		//让弹出层在页面中垂直左右居中(个性)
		popObj.style.top  = arrayPageScroll[1] + (arrayPageSize[3] - arrayConSize[1]) / 2-50 + 'px';
		popObj.style.left = (arrayPageSize[0] - arrayConSize[0]) / 2 -30 + 'px';
	}
	,click : function(el){
		var chbox = document.getElementById('checkpay');
		if(chbox.checked){
			chbox.checked=false;
		}else{
			chbox.checked=true;
		}
	}
});

//所有下拉框
Jes.Select = {
	buss : function(){//商家
		Jes.listDataBySql("bussid","cn_bussiness_query_sql@sel");
	}
	,area : function(){//地区
		Jes.listDataBySql("area","cn_area_query_sql@sel");
	}
	,city : function(param){//城市
		Jes.listDataBySql("city","cn_city_query_sql@sel",param);
	}
	,ind : function(){//行业条目
		Jes.listDataBySql("ind","cn_ind_query_sql@sel");
	}
	,remove : function(elName,value,isChooseAll){
		Jes.alert(elName);Jes.alert(value);
		if(!$(elName)) return;
		if(!JESUtil.isNull(value)){
			var ele = $(elName),_vs = value.split(",");
			for(var i=0;i<_vs.length;i++){
				for(var j=0;j<ele.length;j++){
					if(_vs[i] == ele[j].value){
						ele.remove(j);
						break;
					}
				}
			}
		}else{
			DWRUtil.removeAllOptions(elName);
			if(isChooseAll || isChooseAll == undefined){
				DWRUtil.addOptions(elName,[{ name:'--------------------------', id:''}],"id","name");
			}
		}
	}
}

Jes.Door = {
	init : function(dN,len){
		len =len+1;
		for(var i=1;i<len;i++){
			Jes(dN+i).val=i;
			Jes(dN+i).onclick= function(){
				for(var j=1;j<len;j++){
					Jes(dN+j).className='tabnoseled';
					//Jes.hide(dN+'Div'+j);
				}
				Jes(dN+this.val).className='tabseled';
				//Jes.show(dN+this.val);
			}
		}
	}
}
